/**
 * Project Name:jiuselu-parent
 * File Name:UserCouponController.java
 * Package Name:com.fxp.project.jiuselu.web.business.v1.controller.user
 * Date:2021年11月11日 10:10
 * Copyright (c) 2021, Kai.Wang All Rights Reserved.
 */
package com.fxp.project.jiuselu.web.business.v1.controller.user;

import com.fxp.project.jiuselu.web.base.controller.BaseController;
import com.fxp.project.jiuselu.web.base.request.ReqBase;
import com.fxp.project.jiuselu.web.business.v1.request.user.ReqUserPwd;
import com.fxp.project.jiuselu.web.domain.CommonResult;
import com.fxp.project.jiuselu.web.models.coupon.entity.JslUserCoupon;
import com.fxp.project.jiuselu.web.models.coupon.service.IJslUserCouponService;
import com.fxp.project.jiuselu.web.models.coupon.vo.JslUserCouponVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * ClassName:UserCouponController<br/>
 * Function: 用户的优惠券信息<br/>
 * Date:2021年11月11日 10:10<br/>
 *
 * @author Kai.Wang
 * @version 1.0.0
 * @see
 * @since JDK 8
 */
@RestController
@RequestMapping("/v1/user/coupon")
public class UserCouponController extends BaseController {

    @Autowired
    IJslUserCouponService jslUserCouponService;

    /**
     * showCoupon: 查询当前需要展示的用户的优惠券信息<br/>
     *
     * @param reqBase
     * @param result
     * @return
     * @author Kai.Wang
     * @date 2021/11/11 10:37
     */
    @PostMapping("show")
    @CrossOrigin
    public CommonResult showCoupon(@RequestBody @Validated ReqBase reqBase, BindingResult result) {
        super.checkBindResult(result);
        List<JslUserCouponVo> list = null;
        if(null != super.getCurrentUserInfo()) {
            list = jslUserCouponService.selectJslUserCouponVoForIndexShow(super.getCurrentUserInfo().getUserId());
        }
        return CommonResult.success(list);
    }

    /**
     * list: 查询当前用户的优惠券并展示<br/>
     * @author Kai.Wang
     * @date 2021/11/11 15:20
     * @param reqBase
     * @param result
     * @return
     */
    @PostMapping("list")
    @CrossOrigin
    public CommonResult list(@RequestBody @Validated ReqBase reqBase, BindingResult result) {
        super.checkBindResult(result);
        List<JslUserCouponVo> list = null;
        if(null != super.getCurrentUserInfo()) {
            LocalDateTime expreTime=LocalDateTime.now();
            Long userId = super.getCurrentUserInfo().getUserId();
            System.out.println(userId);
            list = jslUserCouponService.selectJslUserCouponVoList(userId,expreTime);
        }
        return CommonResult.success(list);
    }
}
